Here I want to apply the projected neighbors graph visualization to the pancreas dataset that is used in the scVelo demo and compare it to the visualization on the U2OS dataset.

Use the reticulate package to use scVelo from within R:

Compute velocities on pancreas data using velocyto

Extract spliced and unspliced data

Extract PCA coordinates

Filter genes

Downsample cells to make things easier

Normalize for dimensional reduction

## Warning in if (!class(counts) %in% c("dgCMatrix", "dgTMatrix")) {: the condition
## has length > 1 and only the first element will be used
## Converting to sparse matrix ...
## Normalizing matrix with 1232 cells and 8724 genes

Dimensional reduction

Run velocyto on panc data

Graph visualization

Scores of observed and projected states in PC space

Graph visualization on subset of cells from PC coordinates

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.09331074  min.arrow.size= 0.001866215  max.grid.arrow.length= 0.0610458  done

Graph visualization on subset of cells from gene expression
using common.genes (intersect of oveerdispersed genes, odsGenes, and genes in velocity output)

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.1070039  min.arrow.size= 0.002140077  max.grid.arrow.length= 0.0610458  done

Graph parameters

Effects of changing k, distance measure, similarity measure, and similarity threshold:
Using PC generated graph

L1 vs L2 as distance measure:

#using k=10, similarity=cosine, threshold=0.25
set.seed(1)
graphViz(curr.scores.cellsub,proj.scores.cellsub,10,"L1","cosine",0.25,cell.cols.grph,"L1 distance")

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.09791403  min.arrow.size= 0.001958281  max.grid.arrow.length= 0.0610458  done
graphViz(curr.scores.cellsub,proj.scores.cellsub,10,"L2","cosine",0.25,cell.cols.grph,"L2 distance")

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.1001515  min.arrow.size= 0.002003031  max.grid.arrow.length= 0.0610458  done

Pearson correlation vs Cosine similarity:

#using k=10, distance=L2, threshold=0.25
set.seed(1)
graphViz(curr.scores.cellsub,proj.scores.cellsub,10,"L2","cosine",0.25,cell.cols.grph,"Cosine Similarity")

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.09331074  min.arrow.size= 0.001866215  max.grid.arrow.length= 0.0610458  done
#graphViz(curr.scores.cellsub,proj.scores.cellsub,10,"L2","pearson",0.25,cell.cols.grph,"Pearson Correlation") #need to debug 

Number of out edges k:

#using distance=L2, similarity=cosine, threshold=0.25
ks = c(1,5,10,20,50)
for (k in ks){
  graphViz(curr.scores.cellsub,proj.scores.cellsub,k,"L2","cosine",0.25,cell.cols.grph,paste("K = ",k))
}

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.09113419  min.arrow.size= 0.001822684  max.grid.arrow.length= 0.0610458  done

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.1000589  min.arrow.size= 0.002001178  max.grid.arrow.length= 0.0610458  done

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.1005805  min.arrow.size= 0.002011609  max.grid.arrow.length= 0.0610458  done

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.0938677  min.arrow.size= 0.001877354  max.grid.arrow.length= 0.0610458  done

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.1067673  min.arrow.size= 0.002135346  max.grid.arrow.length= 0.0610458  done

Similarity threshold:

#using k=10, distance=L2, similarity=cosine
ts = c(-1, 0, 0.25, 0.5)
for (t in ts){
  graphViz(curr.scores.cellsub,proj.scores.cellsub,10,"L2","cosine",t,cell.cols.grph,paste("Similarity Threshold = ",t))
}

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.09961078  min.arrow.size= 0.001992216  max.grid.arrow.length= 0.0610458  done

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.09768094  min.arrow.size= 0.001953619  max.grid.arrow.length= 0.0610458  done

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.1035558  min.arrow.size= 0.002071116  max.grid.arrow.length= 0.0610458  done

## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.09911517  min.arrow.size= 0.001982303  max.grid.arrow.length= 0.0610458  done